package com.future.mayi.fragment;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;

import com.future.baselib.utils.CommonUtils;
import com.future.mayi.R;
import com.future.mayi.activity.BaseFragment;
import com.future.mayi.activity.MainActivity;
import com.future.mayi.widget.ClassifyTabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class ClassifyFragment extends BaseFragment {

    @BindView(R.id.view_bar)
    View viewBar;
    @BindView(R.id.tab_layout)
    ClassifyTabLayout tabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;

    private List<Fragment> fragmentList;
    private List<String> listTitle;

    private BrandFragment brandFragment;
    private StyleFragment styleFragment;

    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_classify;
    }

    @Override
    protected void initView() {
        if (MainActivity.statusBar) {
            ViewGroup.LayoutParams layoutParams = viewBar.getLayoutParams();
            layoutParams.height = CommonUtils.getStatusBarHeight(getActivity());
        } else viewBar.setVisibility(View.GONE);

        listTitle = new ArrayList<>(2);
        fragmentList = new ArrayList<>(2);

        listTitle.add("品牌");
        listTitle.add("款式");

        brandFragment = new BrandFragment();
        fragmentList.add(brandFragment);
        styleFragment = new StyleFragment();
        fragmentList.add(styleFragment);

        viewPager.setAdapter(new FragmentPagerAdapter(getChildFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragmentList.get(position);
            }

            @Override
            public int getCount() {
                return fragmentList.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                if (listTitle != null && listTitle.size() > 0) {
                    return listTitle.get(position);
                }
                return super.getPageTitle(position);
            }
        });
        tabLayout.setupWithViewPager(viewPager);
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    public void showFragment() {

    }

    public void refresh() {

    }


    public void onItem(int i) {
        viewPager.setCurrentItem(i);
    }
}
